package com.market.manager.impl;

import java.io.Serializable;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.market.dao.GenericDao;
import com.market.dao.jpa.GenericDaoJpa;
import com.market.domain.BaseObject;
import com.market.domain.Role;
import com.market.manager.GenericManager;
import com.market.web.model.GenericModel;


public abstract class GenericManagerImpl<GD extends GenericDao<BO, PK>, BO extends BaseObject, PK extends Serializable> implements
		GenericManager<BO, PK> {
	/**
	 * Log variable for all child classes. Uses LogFactory.getLog(getClass())
	 * from Commons Logging
	 */
	protected final Log log = LogFactory.getLog(getClass());

	/**
	 * GenericDao instance, set by constructor of child classes
	 */
	protected GD dao;

	public GenericManagerImpl() {
	}

	public GenericManagerImpl(GD genericDao) {
		this.dao = genericDao;
	}
	
	public abstract void setDao(GD dao);
	
	
	public BO fetchOne(PK id) {
			return this.dao.findById(id);
	}



	/**
	 * {@inheritDoc}
	 */
	public List<BO> fetchAll() {
		return this.dao.findAll();
	}

	

	/**
	 * {@inheritDoc}
	 */
	public boolean check(PK id) {
		return dao.existsById(id);
	}

	/**
	 * {@inheritDoc}
	 */
	
	public BO store(BO object)  {
		return dao.save(object);
	}


	public void deleteById(PK id) {
		dao.removeById(id);
	}

	public void delete(BO object) {
		dao.remove(object);		
	}

}
